package com.lianzhihui.romeex.ui.account;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.user.WalletInfo;
import com.lianzhihui.romeex.config.AppConstants;
import com.lianzhihui.romeex.config.MessageEvent;
import com.lianzhihui.romeex.database.DataBaseManager;
import com.lianzhihui.romeex.ui.base.BaseActivity;
import com.lianzhihui.romeex.utils.MyToast;
import com.lianzhihui.romeex.utils.TextUtil;
import com.lianzhihui.romeex.utils.UserUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Description:
 * Author: RAMON
 * CreateDate: 2020/11/3 4:52 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class ChangeNameActivity extends BaseActivity {

    @BindView(R.id.et_name)
    EditText et_name;

    WalletInfo walletInfo;
    String address = "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_name_layout;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        setTitle(getString(R.string.mod_wallet_name));
        address = intent.getStringExtra("address");

        if (TextUtils.isEmpty(address)) {
            MyToast.showToast("无数据");
            finish();
        }
        walletInfo = UserUtils.getUser(address);
        et_name.setText(walletInfo.getUserName());

    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.bt_submit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_submit:
                //修改数据
                String name = et_name.getText().toString().trim();
                if (TextUtils.isEmpty(name)) {
                    toast("请输入钱包名称");
                    return;
                }
                walletInfo.setUserName(name);
                DataBaseManager.up_WalletToDb(walletInfo);
                EventBus.getDefault().post(new MessageEvent(AppConstants.Event.REFRUSH_WALLET, true));
                toast("修改完成");
                finish();
                break;
            default:
                break;
        }
    }

}
